<?php

FLEA::loadClass('Controller_BaseController');

class Controller_Employee extends Controller_BaseController
{
	
    function Controller_Employee() {
        
		$this->table = & FLEA::getSingleton('Table_Employee');
		$dispatcher =& $this->_getDispatcher();
        $user = $dispatcher->getUser();
		if(isset($user['terminal_id'])&&null!=$user['terminal_id'])
			$this->conditions='terminal_id='.$user['terminal_id'];
    }

	function actionWarrant(){
		if(!isset($_POST['employee_id'])) {
			echo "{success:false,data:'授权失败！'}";
			return;
		}
		if(1==$_POST['employee_id']) {
			echo "{success:false,data:'超级用户不能被修改！'}";
			return;
		}
		if(null==$_POST['employee_id']) {
			echo "{success:false,data:'ID无效！'}";
			return;
		}

		$er=& FLEA::getSingleton('Table_EmployeeRole');
		$em_id=(int)$_POST['employee_id'];
		
		if(isset($_POST['roles'])){
			$roles=array();
			$roles=explode(',',$_POST['roles']);
			 __TRY();
					 $er->removeByConditions('employee_id = '.$em_id);
					 foreach($roles as $role){
					   $data=array('employee_id'=>$em_id,'role_id'=>$role);
					   $er->create($data);
					 }
			 $ex = __CATCH();//捕获异常
			 if (__IS_EXCEPTION($ex)) {
				echo "{success:false,data:'授权失败'}";
				return;
			}
			echo "{success:true,data:'授权成功'}";

		}else echo "{success:false,data:'必须选择至少一个权限'}";
	}


}    
?>